package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 *  攻略文章
 */
@Setter
@Getter
public class StrategyDetail extends BaseDomain{
    public static final int STATE_COMMON = 0;//草稿
    public static final int STATE_RELEASE = 1;//发布

    //高级查询中内容归属分类
    public static final Integer TYPE_STRATEGYDETAIL = 1;//攻略

    //标题
    private String title;
    //创建时间
    private Date createTime;
    //发布时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date releaseTime;
    //序号
    private Integer sequence;
    //所属目录
    private StrategyCatalog catalog;
    //封面
    private String coverUrl;
    //状态
    private Integer state = STATE_COMMON;
    //攻略文章内容
    private StrategyContent strategyContent;
    //默认StrategyDetail状态
    private Integer type = TYPE_STRATEGYDETAIL;
    //点击浏览量
    private int browseNum=0;



    public StrategyContent getStrategyContent() {
        if (id != null && strategyContent != null){
            strategyContent.setId(id);
        }
        return strategyContent;
    }

    public String getStateName(){
        String temp = "草稿";
        if(STATE_RELEASE==state){
            temp = "发布";
        }
        return temp;
    }

    public String getJson() {
        //共享给按钮的json数据
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("sequence", sequence);
        map.put("state", state);
        if (catalog != null){
            map.put("catalogId", catalog.id);
            if (catalog.getStrategy() != null){
                map.put("strategyId", catalog.getStrategy().getId());
            }
        }
        map.put("coverUrl", coverUrl);
        return JSON.toJSONString(map);
    }

    

}